
package org.testfire.realm.control.user;

import com.lookingglasssoftware.lgsrealm.LGSChecksum;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.UserTransaction;


/**
 * @author Geoff M. Granum
 * @version 1.0
 */
public class LoginBean {


	/**
	 * The name of the m_user attempting to log in.
	 */
	private String userName;
	/**
	 * The password equivilent of for the m_user attempting to log in.
	 * Recall that for the default setup of this realm, this is HMAC-ed with the
	 * system salt (Defined in NavBean}.
	 */
	private String md5;

	/**
	 * The m_user's password hint
	 */
	private String hint;

	/**
	 * The access level for the m_user; e.g. the group to which they belong.
	 */
	private int access_level;

	/**
	 * We need to talk with the user_db for this task, so we ask for
	 * an entity manager backed by the lgsrealm database
	 * (The persistence-unit with the name "lgsrealm", defined in persistence.xml).
	 */
	@PersistenceContext(unitName = "lgsrealm")
	private static EntityManager em;

	/**
	 * We also want to use a transaction to wrap any database activity.
	 */
	@Resource
	private UserTransaction utx;


	/**
	 * Default constructor.
	 */
	public LoginBean() {
		super();
	}

	/**
	 * The access level for the m_user; e.g. the group to which they belong.
	 *
	 * @return the access level for this m_user.
	 */
	public int getAccess_level() {
		return access_level;
	}

	/**
	 * Get the m_user's password hint.
	 *
	 * @return The m_user's password hint.
	 */
	public String getHint() {
		return hint;
	}

	/**
	 * Get the name of the m_user attempting to log in.
	 *
	 * @return The name of the m_user attempting to log in.
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * Get the password equivilent of for the m_user attempting to log in.
	 * Recall that for the default setup of this realm, this is HMAC-ed with the
	 * system salt (Defined in NavBean}.
	 *
	 * @return The password equivilent of for the m_user attempting to log in.
	 */
	public String getMd5() {
		return md5;
	}

	/**
	 * Set the name of the m_user attempting to log in.
	 *
	 * @param userName The name of the m_user attempting to log in.
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * Set the password equivilent of for the m_user attempting to log in.
	 * Recall that for the default setup of this realm, this is HMAC-ed with the
	 * system salt (Defined in NavBean}.
	 *
	 * @param pwd the password equivilent of for the m_user attempting to log in.
	 */
	public void setPassword(String pwd) {
		this.md5 = LGSChecksum.getMD5(pwd, null);
	}

	/**
	 * Sett the m_user's password hint.
	 *
	 * @param hint The m_user's password hint.
	 */
	public void setHint(String hint) {
		this.hint = hint;
	}

	/**
	 * Set the access level for the m_user; e.g. the group to which they belong.
	 *
	 * @param access_level The access level for the m_user; e.g. the group to which they belong.
	 */
	public void setAccess_level(int access_level) {
		this.access_level = access_level;
	}
}
